package designPattern.singleton.threadLocal;

/*
在单个线程内保证单例
 */
public class ThreadLocalSingleton {
    private static ThreadLocalSingleton instance;
    private ThreadLocalSingleton() {

    }
    private static final ThreadLocal<ThreadLocalSingleton> threadLocalInstance = new ThreadLocal<ThreadLocalSingleton>() {
        @Override
        protected ThreadLocalSingleton initialValue() {
            return new ThreadLocalSingleton();
        }
    };
    public static ThreadLocalSingleton getInstance() {
        return threadLocalInstance.get();
    }
}
